# Maintainer: Andrew Leech <andrew@alelec.net>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=openocd
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.0.r2.g79fdeb3
pkgrel=1
pkgdesc="OpenOCD - Open On-Chip Debugger (mingw-w64)"
arch=('any')
url="http://openocd.sourceforge.net"
options=('!ccache')
# What about ftdi?
depends=("${MINGW_PACKAGE_PREFIX}-hidapi"
         "${MINGW_PACKAGE_PREFIX}-libusb"
         "${MINGW_PACKAGE_PREFIX}-libusb-compat")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "pkg-config"
             "git")
source=("${_realname}::git+http://git.code.sf.net/p/openocd/code")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}"/${_realname}
  git describe --long --tags 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "${srcdir}"/${_realname}
  ./bootstrap
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}

  ../${_realname}/configure \
      --prefix=${MINGW_PREFIX} \
      --{build,host}=${MINGW_CHOST} \
      --disable-dependency-tracking \
      --disable-werror \
      --enable-dummy \
      --enable-jtag_vpi \
      --enable-remote-bitbang \
      --enable-amtjtagaccel \
      --enable-gw16012 \
      --enable-parport \
      --enable-parport-giveio

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install

  # bsdtar can't convert non-ascii filenames to UTF-8 when run in
  # non-UTF-8 locale. It proceeds to pack them anyway embedding raw
  # binary filenames in the traditional tar headers.
}
